Cookbook Community Meetup - 12pm ET / 5pm GMT every week on Wednesdays

Language
Docs

Documentation

Contributors: André Nunes, Luke Cassady-Dorion
Last Updated:

Create Vue Starter Kit

This guide will provide step-by-step instructions to configure your development environment and build a permaweb Vue application.

Prerequisites

Development Dependencies

  • TypeScript (Optional)
  • NPM or Yarn Package Manager

Steps

Create Project

The following command installs and launches create-vue, the official scaffolding tool for Vue projects.

npm init vue@latest
yarn create vue

During the process, you'll be prompted to select optional features such as TypeScript and testing support. I recommend selecting the Vue Router with yes, the rest can be selected as per your preference.

✔ Project name: … <your-project-name>
✔ Add TypeScript? … No / Yes
✔ Add JSX Support? … No / Yes
✔ Add Vue Router for Single Page Application development? … No / *Yes*
✔ Add Pinia for state management? … No / Yes
✔ Add Vitest for Unit testing? … No / Yes
✔ Add Cypress for both Unit and End-to-End testing? … No / Yes
✔ Add ESLint for code quality? … No / Yes
✔ Add Prettier for code formatting? … No / Yes

Change into the Project Directory

cd <your-project-name>

Install Dependencies

npm install
yarn

Setup Router

Vue Router is the official router for Vue.js and seamlessly integrates with Vue. To make it work with Permaweb, switch from a browser history router to a hash router as the URL cannot be sent to the server. Change createWebHistory to createWebHashHistory in your src/router/index.ts or src/router/index.js file.

import { createRouter, createWebHashHistory } from "vue-router";
import HomeView from "../views/HomeView.vue";

const router = createRouter({
	history: createWebHashHistory(import.meta.env.BASE_URL),
	routes: [
		{
			path: "/",
			name: "home",
			component: HomeView,
		},
		{
			path: "/about",
			name: "about",
			component: () => import("../views/AboutView.vue"),
		},
	],
});

export default router;

Setup Build

Configure the build process in the vite.config.ts or vite.config.js file. To serve Permaweb apps from a sub-path (https://[gateway]/[TX_ID]), update the base property to ./ in the config file.

export default defineConfig({
  base: './',
  ...
})

Run the App

Before moving forward, it is crucial to verify that everything is working correctly. Run a check to ensure smooth progress.

npm run dev
yarn dev
it will start a new development server locally on your machine by default it uses `PORT 5173` if this PORT is already in use it may increase the PORT number by 1 (`PORT 5174`) and try again.

Deploy

Generate Wallet

The arweave package is required to generate a wallet.

npm install --save arweave
yarn add arweave

To generate your wallet, run the following command in the terminal:

node -e "require('arweave').init({}).wallets.generate().then(JSON.stringify).then(console.log.bind(console))" > wallet.json

install Irys

Irys is needed to deploy your app to Permaweb, as it offers instant data upload and retrieval.

npm install --save-dev @irys/sdk
yarn add -D @irys/sdk

Arweave Wallet

To upload this app, you may need to add AR and fund your Irys wallet. Visit https://irys.xyzopen in new window and https://www.arweave.org/](https://www.arweave.org/) for more information.

update package.json

{
  ...
  "scripts": {
    ...
    "deploy": "irys upload-dir dist -h https://node2.irys.xyz --wallet ./wallet.json -c arweave --index-file index.html --no-confirmation"
  }
}

Update .gitignore

To protect your funds, it's important to keep your wallet file private. Uploading it to GitHub, where it can potentially become public, could result in your money being leaked. To prevent this, add the wallet.json file to your .gitignore file. And don't forget to save it in a safe place.

echo "wallet.json" >> .gitignore

Run build

It's now time to generate the build.

npm run build
yarn build

Run deploy

Finally we are good to deploy our First Permaweb Application

npm run deploy
yarn deploy

SUCCESS

You should now have a React Application on the Permaweb! Great Job!

Fund Wallet

if your application is greater than 120 kb or you receive the error Not enough funds to send data, you will need to fund you Irys wallet. See https://irys.xyzopen in new window for more information.

Repository

A fully functional example in JavaScript or TypeScript can be found at this location.

Summary

This guide provides a simple step-by-step method to publish a Vue.js app on the Permaweb using Create Vue. If you need additional features Tailwind, consider exploring alternative starter kits listed in the guide to find a suitable solution for your requirements.